<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>readf</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="readclock.html" title="readclock" />
    <link rel="next" href="readfi.html" title="readfi" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">readf</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="readclock.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="readfi.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="readf"></a>
      <div class="titlepage"></div>
      <a id="IndexReadf" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">readf</span>
        </h2>
        <p>readf — 
      Read a line of text from an external file.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp141333328"></a>
        <h2>Description</h2>
        <p>
      Read a line of text from an external file once each k-cycle.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp141337264"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">Sres, kline <span class="command"><strong>readf</strong></span> ifilname</pre>
      </div>
      <div class="refsect1">
        <a id="idp141339472"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>ifilname</em></span> -- an integer N denoting a file
      named "input.N" or a character string (in double quotes, spaces
      permitted) denoting the external file name. For a string, it may
      either be a full path name with directory specified or a simple
      filename.  In the later case, the file is sought first in the
      current directory, then in SSDIR, and finally in SFDIR.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp141408288"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>Sres</em></span> -- output of the line read from
      <span class="emphasis"><em>ifilname</em></span>. 
    </p>
        <p>
      <span class="emphasis"><em>kline</em></span> -- line number, or -1 when end of file has been reached. 
    </p>
        <p>
      This opcode allows a line of text to be read from a named
      external file.  There may be any number of
      <span class="emphasis"><em>readf</em></span> opcodes in an instrument or orchestra
      but they read separately from the same or different files.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp141412176"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the readf opcode. It uses the file <a class="ulink" href="examples/readf.csd" target="_top"><em class="citetitle">readf.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp141414032"></a>
          <p class="title">
            <strong>Example 740. Example of the readf opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
-n
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
<span class="oblock">instr</span> 1
  Swd           <span class="opc">pwd</span>
                <span class="opc">printf_i</span>      "Working directory is '<span class="op">%</span>s'\n", 1, Swd
                <span class="opc">prints</span>        "Reading myself <span class="op">=</span>)<span class="op">:</span>\n"
<span class="olabel">read</span><span class="op">:</span>
  Sline, kLinNum <span class="opc">readf</span> "readf.csd"
                <span class="opc">printf</span> "Line <span class="op">%</span>d<span class="op">:</span> <span class="op">%</span>s", kLinNum, kLinNum, Sline
  <span class="octrl">if</span> kLinNum <span class="op">!=</span> <span class="op">-</span>1 then
                <span class="octrl">kgoto</span> <span class="olabel">read</span>
  <span class="octrl">else</span> 
                <span class="opc">turnoff</span>
  <span class="octrl">endif</span>
<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span>1 0 1
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp141418320"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="readfi.html" title="readfi"><em class="citetitle">readfi</em></a>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp141420400"></a>
        <h2>Credits</h2>
        <p>John ffitch and Joachim Heintz</p>
        <p>2012; new in 5.17.12</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="readclock.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="readfi.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">readclock </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> readfi</td>
        </tr>
      </table>
    </div>
  </body>
</html>
